<?php
/*
+--------------------------------------------------------------------------
|   jQuery simTaco plugin - A port of jQuery Taconite plugin by M. Alsup
|   http://malsup.com/jquery/taconite/
|   
|   There are two important differences!
|   1. simTaco can send unlimited options to the server
|   2. simTaco works onDemand (bind) and not by listener - that caused issues with other scripts in my work
|   
|   Additionally and most important, simTaco works with latest jQuery - test up to v1.7.1
|   
|   simTaco allowes the fast developpment of extended user interfaces, like for example the one from Facebook.
|   Multiple DOM updates, content changes and style changes can be 
|   performed by a single AJAX call. This call can transmit as many variables as needed!
|   The server responds with an XML file, that holds all changes intended.
|   
|   ========================================
|   simTaco Copyright (c) 2012 by Hensel Hartmann
|   http://www.simpeligent.ch
|   ========================================
|   simTaco is Dual licensed under the MIT and GPL licenses:
|   http://www.opensource.org/licenses/mit-license.php
|   http://www.gnu.org/licenses/gpl.html
|    
|   File: simTaco_controller.php
|   this file should deliver valid, wellformed XML
|
|   With some finesse, you can manage to work with CMV Pattern if needed for huge applications
|   but for most applications, that is not needed - mostly with included files, that hold certain parts of the code, you can clean up the code enough
|   Additionally it is possible to create the XML with a php class to get it oo if you prefere
|   most packages, compatible with taconite, can also be used with simTaco.
|
|   File: simTaco_controller.php
|   demo XML
+--------------------------------------------------------------------------
*/



$decoded = json_decode(stripslashes($_GET['target']), true);
//var_dump($decoded);

?>




<simTaco>

    <slideDown select="#debug" arg1="slow" />
    <replaceContent select="#debug"><![CDATA[
    <pre>
        <?php print_r($decoded); ?>
        at <?php echo time(); ?>
    </pre> 
    
    ]]></replaceContent>


<?php
        if($decoded['screwWithDOM'])
        {
?> 
            <after select="#result2"> 
                This text will go AFTER the #result2 div. 
            </after> 
            
            <before select="#result2"> 
                <div>This div will go BEFORE the #result2 div.</div> 
            </before> 
            
            <append select="#result2"> 
                <span>This span is APPENDED inside #result2 and an other div with dotted border was wrapped around</span> 
            </append> 
            
            <wrap select="#result2 span"> 
                <div style="border: 2px dashed #00F"></div> 
            </wrap> 
<?php
        }
        if($decoded['changeWidth'])
        {
?> 
            <css select="div" arg1="width" arg2="<?php echo $decoded['changeWidth'] ?>" />
            <css select="p" arg1="width" arg2="<?php echo $decoded['changeWidth'] ?>" />
            <css select="code" arg1="width" arg2="<?php echo $decoded['changeWidth'] ?>" />
<?php
        }
        if($decoded['changeColor']&&$decoded['selector'])
        {
?>
            <css select="#<?php echo $decoded['selector'] ?>" arg1="border" arg2="1px solid black" />
            <css select="#<?php echo $decoded['selector'] ?>" arg1="background" arg2="<?php echo $decoded['changeColor'] ?>" />
<?php
        }
        if($decoded['want_an_alert']=='yes please')
        {
?>
            <eval><![CDATA[
                alert('this is a JS-Alert, called from server side with simTaco at <?php echo date("H:i:s",time()); ?>');
            ]]></eval>
<?php
        }

if($decoded['page'])
{
    switch($decoded['page'])
    {
        case'main':
?>
        <slideUp select="#result2" arg1="slow" />
        <slideUp select="#anotherElement" arg1="slow" />
        <slideDown select="#result" arg1="slow" />
        <replaceContent select="#result"><![CDATA[
                This content was loaded in to the div "#result" at <?php echo time(); ?>
                <br />
                The transmitted value of page was "<?php echo $decoded['page']; ?>"
                <br />
                The transmitted value of ID was "<?php echo $decoded['id']; ?>"
                <br />
                The transmitted value of foo was "<?php echo $decoded['foo']; ?>"
                <br /><br />
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"page":"third","id":"123","foo":"Yet Another <b>Foo Bar</b> YAFB"}' >click test4 - fill "anotherElement"</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"red"}' >change bgcolor red</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"blue"}' >change bgcolor blue</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"white"}' >change bgcolor white</p>
        ]]></replaceContent>
<?php    
        break;
    
        case'second':
?>
            <slideUp select="#result" arg1="slow" />
            <slideUp select="#anotherElement" arg1="slow" />
            <slideDown select="#result2" arg1="slow" />
            <replaceContent select="#result2"><![CDATA[
                This content was loaded in to the div "#result2" at <?php echo time(); ?>
                <br />
                The transmitted value of page was "<?php echo $decoded['page']; ?>"
                <br />
                The transmitted value of ID was "<?php echo $decoded['id']; ?>"
                <br /><br />
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"screwWithDOM":1}' >click here to screw around with the DOM</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result2","changeColor":"red"}' >change bgcolor red</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result2","changeColor":"blue"}' >change bgcolor blue</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result2","changeColor":"white"}' >change bgcolor white</p>
    
            ]]></replaceContent>
<?php    
        break;
    
        case'third':
?>
            <slideUp select="#result" arg1="slow" />
            <slideUp select="#result2" arg1="slow" />
            <slideDown select="#anotherElement" arg1="slow" />
            <replaceContent select="#anotherElement"><![CDATA[
                This content was loaded in to the div "#anotherElement" at <?php echo time(); ?>
                <br />
                The transmitted value of page was "<?php echo $decoded['page']; ?>"
                <br />
                The transmitted value of ID was "<?php echo $decoded['id']; ?>"
                <br />
                The transmitted value of foo was "<?php echo $decoded['foo']; ?>"
                <br /><br />
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"anotherElement","changeColor":"red"}' >change bgcolor red</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"anotherElement","changeColor":"blue"}' >change bgcolor blue</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"anotherElement","changeColor":"white"}' >change bgcolor white</p>
            ]]></replaceContent>
<?php    
        break;
    
        case'bigshow_lol':
?>
            

            <slideDown select="#result" arg1="slow" />
            <replaceContent select="#result"><![CDATA[
                simTaco_controller response result
                <br />
                The transmitted value of page was "<?php echo $decoded['page']; ?>"
                <br /><br />
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"red"}' >change bgcolor red</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"blue"}' >change bgcolor blue</p>
                <p class="someElement" simTaco_path="simTaco_controller.php" simTaco_options='{"selector":"result","changeColor":"white"}' >change bgcolor white</p>
            ]]></replaceContent>
            <css select="#result" arg1="border" arg2="6px solid red" />
            <slideUp select="#result" arg1="slow" />
            <slideDown select="#result" arg1="slow" />
            <css select="#result" arg1="width" arg2="800px" />
            <css select="#result" arg1="background" arg2="silver" />
            <slideUp select="#result" arg1="slow" />
            <slideDown select="#result" arg1="slow" />
            


            <slideDown select="#result2" arg1="slow" />
            <replaceContent select="#result2"><![CDATA[
                The transmitted value of page was "<?php echo $decoded['page']; ?>"<br />
                simTaco_controller response is here. <br />
                Some Specialchars: öä$ü ' " ! <br />
                Some HTML: <strong>foo</strong><br />
                in div "#result2"
                <br /><br /><br /><br /><br />bla
            ]]></replaceContent>
            <css select="#result2" arg1="border" arg2="6px solid green" />
            <slideUp select="#result2" arg1="slow" />
            <slideDown select="#result2" arg1="slow" />
            <slideUp select="#result2" arg1="slow" />
            <slideDown select="#result2" arg1="slow" />
            <css select="#result2" arg1="background" arg2="silver" />
            <css select="#result2" arg1="border" arg2="1px solid black" />
            
            <slideDown select="#anotherElement" arg1="slow" />
            <css select="#anotherElement" arg1="width" arg2="500px" />
            <css select="#anotherElement" arg1="border" arg2="2px solid red" />
            <css select="#anotherElement" arg1="background" arg2="silver" />
            <replaceContent select="#anotherElement"><![CDATA[
                The transmitted value of page was "<?php echo $decoded['page']; ?>"
                <br />
                    <table border="2">
                        <tr>
                            <td>11</td>
                            <td>22</td>
                        </tr>
                    </table>
                <br />anotherElement
                
            ]]></replaceContent>
<?php
        break;
        



        default:
?>
            <slideUp select="#result2" arg1="slow" />
            <slideUp select="#anotherElement" arg1="slow" />
            <slideDown select="#result" arg1="slow" />
            <replaceContent select="#result"><![CDATA[
                the requested page "<?php echo $decoded['page']; ?>" was not found at <?php echo time(); ?>
            ]]></replaceContent>
<?php    
        break;
    
    }
}
?>



</simTaco>


